package org.chuan.hisports.service.Imp;

import org.chuan.hisports.dao.CoachDao;
import org.chuan.hisports.entity.*;
import org.chuan.hisports.service.CoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CoachServiceImp implements CoachService {

    @Autowired
    CoachDao coachDao;
    @Override
    public List<CUList> selectApply(String uid){
        List<CUList> list = coachDao.selectApply(uid);
        return list;
    }

    @Override
    public List<CUList> selectAll(String uid){
        List<CUList> list = coachDao.selectAll(uid);
        return list;
    }

    @Override
    public CoachInfo selectByCid(String cid){
        CoachInfo coachInfo = coachDao.selectCoaById(cid);
        return coachInfo;
    }

    @Override
    public List<CoachInfo> selectCoachAll(){
        List<CoachInfo> list = coachDao.selectCoachAll();
        return list;
    }

    @Override
    public List<AdCoach> selectAdCoach(){
        List<AdCoach> list = coachDao.selectAdCoach();
        return list;
    }

    @Override
    public List<UserInfo> selectUserByCid(String cid){
        List<UserInfo> list = coachDao.selectUserByCid(cid);
        return list;
    }

    //查询教练账号是否存在
    @Override
    public boolean selectIsExsit(String phone){
        String localphone = coachDao.selectIsExsit(phone);
        if (localphone==null)
            return false;
        return true;
    }
    //插入账号,插入教练信息
    @Override
    public boolean insertCoach(String phone, String password){
        Coach coach = new Coach();
        coach.setPhone(phone);
        coach.setPassword(password);
        coachDao.register(coach);
        String cid = coach.getId()+"";
        System.out.println(cid);

        String name = "请尽快更改个人信息";
        CoachInfo coachInfo = new CoachInfo();
        coachInfo.setCid(cid);
        coachInfo.setName(name);
        coachDao.insertCoachInfo(coachInfo);
        return true;
    }

    //教练登录
    @Override
    public CoachInfo login(String phone,String password){
        CoachInfo coachInfo = coachDao.login(phone, password);
        return coachInfo;
    }
    //教练增删改查会员的健身方案
    @Override
    public Scheme selectByUid( String uid){
        Scheme scheme = coachDao.selectByUid(uid);
        return scheme;
    };
    @Override
    public void insertToUid(String uid,
                            String walking,
                            String runing,
                            String training,
                            String bike){
        coachDao.insertToUid(uid, walking, runing, training, bike);
    };
    @Override
    public void updataScheme(String uid,
                             String walking,
                             String runing,
                             String training,
                             String bike){
        coachDao.updataScheme(uid, walking, runing, training, bike);
    };

    @Override
    public void updataInfo(String cid,String name,String able,String slogan,
                           String weight,String height,String tyear,String age){
        coachDao.updataInfo(cid, name, able, slogan, weight, height, tyear, age);
    }

    @Override
    public void updataPicture(String cid,String picture){
        coachDao.updataPicture(cid,picture);
    }
}
